<?php

function reequipment_user_report_pm_complete()
{    
    if (!xarSecurityCheck('EditEquipment', 1)) return;
    $data = array();
     // Get company_id
    if (!xarVarFetch('company_id', 'int:1:', $company_id, '', XARVAR_NOT_REQUIRED)) return; 
	if (!xarModAPIFunc('reequipment', 'user', 'getcompanyid', array('company_id_from_url' => $company_id))) return;
	$company_id = xarSessionGetVar('company_id');
	xarTplSetPageTitle(xarML('Completed PM'));
	// Get PM Data
	$data['pms'] = xarModAPIFunc('reequipment', 'user', 'getmaintenance', array('company_id' => $company_id, 'complete' => true, 'scheduled' => true));
	
	foreach ($data['pms'] as $key => $item) {
    	$data['pms'][$key]['date_due_raw'] = strtotime($item['date_due']);
    	$data['pms'][$key]['date_complete_raw'] = strtotime($item['date_complete']);
    	if ($data['pms'][$key]['date_due_raw'] < $data['pms'][$key]['date_complete_raw']){
    		$data['pms'][$key]['overdue'] = xarML('Yes');
    	} else {
    		$data['pms'][$key]['overdue'] = '';
    	}
    }
	// return var_export($data['pms']);
    // Company Name
	$companies = xarModAPIFunc('reequipment', 'user', 'getrel', array('company_id' => $company_id));
	foreach($companies as $var){
		$data['company_name'] = $var['company_name'];
	}
    return $data;
}

?>